package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysArtistProject;
import com.ruoyi.system.service.ISysArtistProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 艺人与项目关系Controller
 * 
 * @author cooc
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/system/artistProject")
public class SysArtistProjectController extends BaseController
{
    @Autowired
    private ISysArtistProjectService sysArtistProjectService;

    /**
     * 查询艺人与项目关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysArtistProject sysArtistProject)
    {
        startPage();
        List<SysArtistProject> list = sysArtistProjectService.selectSysArtistProjectList(sysArtistProject);
        return getDataTable(list);
    }

    /**
     * 导出艺人与项目关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:export')")
    @Log(title = "艺人与项目关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysArtistProject sysArtistProject)
    {
        List<SysArtistProject> list = sysArtistProjectService.selectSysArtistProjectList(sysArtistProject);
        ExcelUtil<SysArtistProject> util = new ExcelUtil<SysArtistProject>(SysArtistProject.class);
        util.exportExcel(response, list, "艺人与项目关系数据");
    }

    /**
     * 获取艺人与项目关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysArtistProjectService.selectSysArtistProjectById(id));
    }

    /**
     * 新增艺人与项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:add')")
    @Log(title = "艺人与项目关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysArtistProject sysArtistProject)
    {
        return toAjax(sysArtistProjectService.insertSysArtistProject(sysArtistProject));
    }

    /**
     * 修改艺人与项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:edit')")
    @Log(title = "艺人与项目关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysArtistProject sysArtistProject)
    {
        return toAjax(sysArtistProjectService.updateSysArtistProject(sysArtistProject));
    }

    /**
     * 删除艺人与项目关系
     */
    @PreAuthorize("@ss.hasPermi('system:artistProject:remove')")
    @Log(title = "艺人与项目关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysArtistProjectService.deleteSysArtistProjectByIds(ids));
    }
}
